import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;

public class GotoForm extends Form implements CommandListener 
{
	private static final Command CMD_OK = new Command("OK", Command.OK, 1);
    private static final Command CMD_CANCEL = new Command("Cancel", Command.CANCEL, 1);
    private Table parent;
    private Display display;
    private TextField rowTextBox;
    private TextField columnTextBox;
    private Spacer spacer;

    public GotoForm(Table parent, Display display) 
	{
		super("Enter Row and column");

		rowTextBox = new TextField("Row Index",null,3,TextField.NUMERIC);
		columnTextBox = new TextField("Column Index",null,3,TextField.NUMERIC);
		spacer = new Spacer(0,50);

        this.parent = parent;
        this.display = display;
        addCommand(CMD_OK);
        addCommand(CMD_CANCEL);

		append(spacer);
		append(rowTextBox);
		append(columnTextBox);

        setCommandListener(this);
    }

    public void commandAction(Command c, Displayable d) 
	{
		if (c == CMD_OK) 
		{
			int row = Integer.parseInt(rowTextBox.getString());
			int column = Integer.parseInt(columnTextBox.getString());
			if(row < 925 && column < 125)
			{		
				parent.setRowColumn(row,column);
	            display.setCurrentItem(parent);
			}
        }
		else if (c == CMD_CANCEL) 
		{
            display.setCurrentItem(parent);
        }
    }
}
